/**
 * 
 * @Project le cOeur - Data Virtualization
 * @Date 08.12.2012
 * @Author Aebi Pascal, Kocher Marc
 * @School BFH-TI Biel, Bachelor Thesis
 *
 */

package main.framework.setting;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Properties;
import java.util.logging.Logger;

/**
 *  This class reads a config file and makes the different fields available in the application
 */
public class Config {

	private static final Logger LOGGER = Logger.getLogger("SysLogger");
	private static final String CONFIG_FILE = "server.config.properties";
	
	// Port configuration
	public static String ENABLE_DEFAULT_PORTS;
	public static String DEFAULT_HTTP_PORT;
	public static String DEFAULT_TLS_PORT;
	
	// Resource settings
	public static String ROOT_RESOURCE_PATH;
	public static String RESOURCE_XML_FILE_PATH;
	public static String RESOURCE_XSD_FILE_PATH;
	public static String RESOURCE_METHOD_PATH;
	
	// Security settings
	public static String ENABLE_CLIENT_AUTHENTICATION;
	public static String KEY_STORE_ALGORITHM;
	public static String KEY_STORE_TYPE;
	public static String KEY_STORE_PATH;
	public static String KEY_STORE_PW;
	public static String TRUST_STORE_ALGORITHM;
	public static String TRUST_STORE_TYPE;
	public static String TRUST_STORE_PATH;
	public static String TRUST_STORE_PW;
	
	// Database settings
	public static String DB_HOST;
	public static String DB_PORT;
	public static String DB_NAME;
	public static String DB_USER;
	public static String DB_USER_PW;
	
	static {
		try {
			Properties properties = new Properties();
			properties.load(new FileInputStream(CONFIG_FILE));
			for (Field field : Config.class.getFields()){
				try {
					field.set(Config.class, properties.getProperty(field.getName()));
				} catch (IllegalAccessException e) {
					LOGGER.severe(e.getMessage());
					System.exit(1);
				}
			}
		} catch (FileNotFoundException e) {
			LOGGER.severe(e.getMessage());
			System.exit(1);
		} catch (IOException e) {
			LOGGER.severe(e.getMessage());
			System.exit(1);
		}
	}

}
